package reflect;

import java.util.Scanner;

public class ReflectDemo2 {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        Person person = new Person();
        System.out.println(person);


        Scanner scan=new Scanner(System.in);
        System.out.println("请输入一个类名：");
        String str=scan.nextLine();
        //获取类对象
        Class c = Class.forName(str);
        /*
        使用newInstance实例化该类对象
        使用该类的无参构造器实例化该对象，并将实例化后的对象向上造型为Object
        */
        Object o = c.newInstance();

        System.out.println(o);

    }
}
